<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>    
    <div id="app">      
        <p>age:{{age}}</p>
        <p>isAdult：{{isAdult}}</p>
        <input type="button" value="修改Age" @click="changeAge" >
        
    </div>
</body>
</html>

<script src="./js/vue.global.js"></script>
<script>    

     const {createApp,ref,reactive,watch,watchEffect,onMounted,onBeforeMount} = Vue;

    let app = createApp({
        setup(){

            let age = ref(16);
            let isAdult = ref(false);

            
            // 1、watchEffect回调函数里，使用哪个响应式数据，那么就会监听哪个数据。

            function changeAge(){
                age.value++;
            }

            onBeforeMount(()=>{
                console.log("组件初次渲染前：onBeforeMount");
            });

            onMounted(()=>{
                console.log("组件初次渲染后：onMounted");
            })

            watchEffect(()=>{                
                console.log("watchEffect：age.value",age.value);
                isAdult.value = age.value>=18?true:false;
            },{
                flush: 'post'
            });
            
            return {
                age,changeAge,isAdult
            }
        }
    })

    app.mount("#app");

</script>